package view;

import model.Resource;
import javax.swing.*;
import java.awt.*;

public class ResourceDetailsDialog extends JDialog {
    public ResourceDetailsDialog(JFrame parent, Resource resource) {
        super(parent, "资源详情", true);
        setSize(500, 400);
        setLocationRelativeTo(parent);

        initUI(resource);
    }

    private void initUI(Resource resource) {
        JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
        mainPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));

        // 标题区域
        JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        JLabel titleLabel = new JLabel(resource.getTitle());
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
        titlePanel.add(titleLabel);

        // 类型标签
        JLabel typeLabel = new JLabel(resource.getClass().getSimpleName());
        typeLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        typeLabel.setForeground(Color.GRAY);
        titlePanel.add(typeLabel);

        // 状态标签
        JLabel statusLabel = new JLabel(resource.isAvailable() ? "可用" : "已借出");
        statusLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
        statusLabel.setForeground(resource.isAvailable() ? Color.GREEN : Color.RED);
        titlePanel.add(statusLabel);

        mainPanel.add(titlePanel, BorderLayout.NORTH);

        // 详情区域
        JTextArea detailsArea = new JTextArea(resource.getDetails());
        detailsArea.setEditable(false);
        detailsArea.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        detailsArea.setLineWrap(true);
        detailsArea.setWrapStyleWord(true);

        mainPanel.add(new JScrollPane(detailsArea), BorderLayout.CENTER);

        // 按钮区域
        JButton closeButton = new JButton("关闭");
        closeButton.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        closeButton.addActionListener(e -> dispose());

        JPanel buttonPanel = new JPanel();
        buttonPanel.add(closeButton);
        mainPanel.add(buttonPanel, BorderLayout.SOUTH);

        add(mainPanel);
    }
}